/**
 * 文章发表模块接口列表
 */
import base from './base'; // 导入接口域名列表
import http from '../utils/http'; // 导入http中创建的axios实例

const talk = {    
    async getUserList(param) {
        try {
            const res = await http.get(`${base.url.core}/user/list`, {
                params:param
            });
            if (res.data) {
                return res.data.result;
            }
        }
        catch (err) {
            return Promise.reject(err);
        }
        
    },
    async addOrUpdateUser(params) {
        try {
            const res = await http.post(`${base.url.core}/user/add_update`,params);
            if (res.data) {
                //console.log(res)
                return res.data.result;
            }
        }
        catch (err) {
            return Promise.reject(err);
        }
    },    
    async addCall(params) {
        try {
            let formData = new FormData
            formData.append("uid",params.uid);
            formData.append("call",params.call);
            const res = await http.post(`${base.url.core}/user/add_call`,formData);
            if (res.data) {
                //console.log(res)
                return res.data.result;
            }
        }
        catch (err) {
            return Promise.reject(err);
        }
    },
    async delUser(params) {
        try {
            let formData = new FormData
            formData.append("uid",params.uid);            
            const res = await http.post(`${base.url.core}/user/del`,formData);
            if (res.data) {
                //console.log(res)
                return res.data.result;
            }
        }
        catch (err) {
            return Promise.reject(err);
        }
    },
    async delCall(params) {
        try {
            let formData = new FormData
            formData.append("id",params.id);
            const res = await http.post(`${base.url.core}/user/del_call`,formData);
            if (res.data) {
                //console.log(res)
                return res.data.result;
            }
        }
        catch (err) {
            return Promise.reject(err);
        }
    },
    async getIntentionList(param) {
        try {
            const res = await http.get(`${base.url.core}/intention/list`, {
                params:param
            });
            if (res.data) {
                return res.data.result;
            }
        }
        catch (err) {
            return Promise.reject(err);
        }
        
    },
    async addOrUpdateIntention(params) {
        try {
            const res = await http.post(`${base.url.core}/intention/add_update`,params);
            if (res.data) {
                //console.log(res)
                return res.data.result;
            }
        }
        catch (err) {
            return Promise.reject(err);
        }
    },    
    async addOrUpdateQuery(params) {
        try {
            let formData = new FormData
            formData.append("id",params.id);
            formData.append("sid",params.sid);       
            formData.append("q",params.query);
            formData.append("answer",params.answer);
            formData.append("scores",params.scores);
            formData.append("mode",params.mode);
            const res = await http.post(`${base.url.core}/query/add_update`,formData);
            if (res.data) {
                //console.log(res)
                return res.data.result;
            }
        }
        catch (err) {
            return Promise.reject(err);
        }
    },
    async delIntention(params) {
        try {
            let formData = new FormData
            formData.append("sid",params.sid);                 
            const res = await http.post(`${base.url.core}/intention/del`,formData);
            if (res.data) {
                //console.log(res)
                return res.data.result;
            }
        }
        catch (err) {
            return Promise.reject(err);
        }
    },
    async delQuery(params) {
        try {
            let formData = new FormData
            formData.append("id",params.id);
            const res = await http.post(`${base.url.core}/query/del`,formData);
            if (res.data) {
                //console.log(res)
                return res.data.result;
            }
        }
        catch (err) {
            return Promise.reject(err);
        }
    }
}
export default talk;
